package http;

import com.google.gson.internal.$Gson$Types;

import org.json.JSONObject;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created by hqw on 2015/9/8.
 */
public  abstract class ResultCallback<T>
{
    Type mType;

    public ResultCallback()
    {
        mType = getSuperclassTypeParameter(getClass());
    }

    static Type getSuperclassTypeParameter(Class<?> subclass)
    {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class)
        {
            throw new RuntimeException("Missing type parameter.");
        }
        ParameterizedType parameterized = (ParameterizedType) superclass;
        return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
    }

    public abstract void onSuccess(JSONObject res, T response);

    public abstract void onError(JSONObject errorResponse);

    public  void onCancel(){
     //TODO 无网络连接，直接取消请求连接
    }

    public void onFailure() {
        //TODO 请求失败
    }
}
